package service

import (
	"github.com/toolkits/pkg/logger"
	"strconv"
)

type SysAdmin struct {
	Info     SysUser
	userList []SysUser
}

// CreateUsers
// 批量创建用户
func (a *SysAdmin) CreateUsers() (successfulList []string, failedList []string, err error) {
	for _, user := range a.userList {
		userId, err := user.Create()
		if err != nil {
			logger.Error(err)
			failedInfo := user.UserName + "(" + err.Error() + ")"
			failedList = append(failedList, failedInfo)

		} else {
			successfulList = append(successfulList, user.UserName)
		}
		logger.Info(userId)
	}
	return successfulList, failedList, nil
}

func (a *SysAdmin) AddUser(srcUser ...SysUser) {
	a.userList = append(a.userList, srcUser...)
}

// UpdateUsers
// 批量修改用户
func (a *SysAdmin) UpdateUsers() (successfulList []string, failedList []string, err error) {
	for _, user := range a.userList {
		err = user.Update()
		if err != nil {
			logger.Error(err)
			failedInfo := strconv.FormatInt(user.ID, 10) + ":" + user.UserName + "(" + err.Error() + ")"
			failedList = append(failedList, failedInfo)

		} else {
			successfulList = append(successfulList, strconv.FormatInt(user.ID, 10))
		}
	}
	return successfulList, failedList, nil
}
